/*
visqrt
Copyright (C) 2010  Bhupendra Aole

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
/*
 * File: Disk.java
 * Author: Bhupendra Aole
 * Date: Aug 29, 2010: 
 * 
 * Revisions:
 * ----------
 */

package aole.object;

import aole.math.Vec3;

/**
 * 
 */
public class Disk extends Plane {
	// center of the disk
	protected Vec3 center = new Vec3();
	protected float r = 0f;
	protected float r2 = 0f;

	/* (non-Javadoc)
	 * @see aole.object.Object3D#calcIntersection(aole.math.Vec3, aole.math.Vec3)
	 */
	@Override
	public float calcIntersection (Vec3 p, Vec3 d) {
		float t = super.calcIntersection(p, d);
		if (t > 0f) {
			Vec3 ip = p.getAdded(d.getScaled(t));
			Vec3 dist = ip.getSubtracted(center);
			if (dist.lengthSqr() < r2)
				return t;
		}
		return -1f;
	}

	public void readcenter (String s) {
		center.read(s);
		D = (float) Math.sqrt(Vec3.dot(center, normal));
	}

	public void readradius (String s) {
		r = Float.parseFloat(s);
		r2 = r * r;
	}

	@Override
	public void readnormal (String s) {
		super.readnormal(s);
		D = -Vec3.dot(center, normal);
	}
}
